package com.xoa.controller.task;


import com.xoa.model.task.TaskFeedback;
import com.xoa.model.task.TaskManage;
import com.xoa.model.users.Users;
import com.xoa.service.task.TaskManageService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *<p>
 *  任务督办
 *</p>
 *@author 王禹萌
 *@since  2019-12-21
 */
@Controller
@RequestMapping("/task")
public class TaskManageController {
    @Autowired
    private TaskManageService taskManageService;

    @RequestMapping("/taskManage")
    public String IndexTaskManage(){
        return "app/task/myTask";
    }
    @RequestMapping("/taskSubordinate")
    public String IndexTaskSubordinate(){
        return "app/task/taskSubordinate";
    }
    @RequestMapping("/taskAnalysis")
    public String IndexTaskAnalysis(){
        return "app/task/taskAnalysis";
    }
    @RequestMapping("/taskReport")
    public String IndexTaskReport(){
        return "app/task/taskReport";
    }

    /**
     * 新增任务
     * @param request
     * @param taskManage
     * @return
     */
    @ResponseBody
    @RequestMapping("/addTaskManage")
    public ToJson addTaskManage(HttpServletRequest request, TaskManage taskManage){
        return taskManageService.addTaskManage(request,taskManage);
    }

    /**
     * 查询负责人
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryUser")
    public BaseWrapper queryUser(HttpServletRequest request){
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        BaseWrapper baseWrapper = new BaseWrapper();
        baseWrapper.setData(users);
        baseWrapper.setFlag(true);
        return baseWrapper;
    }

    /**
     * 更新任务
     * @param request
     * @param taskManage
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateTaskManage")
    public ToJson updateTaskManage(HttpServletRequest request, TaskManage taskManage){
        return taskManageService.updateTaskManage(request,taskManage);
    }

    /**
     * 按任务Id查询任务展示列表
     * @param request
     * @param taskId
     * @return
     */
   @ResponseBody
   @RequestMapping("/queryTaskManageByTaskId")
   public ToJson queryTaskManageByTaskId(HttpServletRequest request, int taskId){
       return taskManageService.queryTaskManageByTaskId(request,taskId);
   }

    /**
     * 新增反馈及回复信息
     * @param request
     * @param taskFeedback
     * @return
     */
   @ResponseBody
   @RequestMapping("/addTaskFeedback")
    public ToJson addTaskFeedback(HttpServletRequest request,TaskFeedback taskFeedback){
        return taskManageService.addTaskFeedback(request,taskFeedback);
   }

    /**
     * 按照任务id删除id
     * @param request
     * @param taskId
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteTaskManage")
    public ToJson deleteTaskManage(HttpServletRequest request,int taskId){
        return taskManageService.deleteTaskManage(request,taskId);
    }

    /**
     * 查询任务主页面
     * @param request
     * @param typeId
     * @param taskManage
     * @param myTask
     * @param implementation
     * @param taskNameStr
     * @param manageNameStr
     * @return
     */
    @ResponseBody
    @RequestMapping("/queryTask")
    public ToJson queryTask(HttpServletRequest request,int typeId,TaskManage taskManage,int myTask,int implementation,String taskNameStr,String manageNameStr){
        return taskManageService.queryTask(request,typeId,taskManage,myTask,implementation,taskNameStr,manageNameStr);
    }

    /**
     * 任务报表查询及导出
     * @param request
     * @param pageSize
     * @param page
     * @param useFlag
     * @return
     */
    @ResponseBody
    @RequestMapping("/reportTask")
    public ToJson reportTask(HttpServletResponse response,HttpServletRequest request, Integer pageSize,
                             Integer page, Boolean useFlag, int temp,String userId,String deptId,int statisObject,String startDate,String endDate){
        return taskManageService.reportTask(response,request,pageSize,page,useFlag,temp,userId,deptId,statisObject,startDate,endDate);
    }

    @ResponseBody
    @RequestMapping("/reportTaskType")
    public ToJson reportTaskType(HttpServletResponse response,HttpServletRequest request, Integer pageSize,
                             Integer page, Boolean useFlag, String userId,int temp){
        return taskManageService.reportTaskType(response,request,pageSize,page,useFlag,userId,temp);
    }

    /**
     * 催办/批量催办
     * 王禹萌
     * @param taskId 任务id
     * @param urgeContent 催办内容
     * @param remind 提醒人（负责人、参与人）
     * @param otherPeople 其他人
     * @param reminder 1内部消息 2.手机短信
     * @return
     */
    @ResponseBody
    @RequestMapping("/batchUrgeTask")
    public ToJson batchUrgeTask(HttpServletRequest request,String taskId,String urgeContent,String remind,String otherPeople,String reminder){
        return taskManageService.batchUrgeTask(request,taskId,urgeContent,remind,otherPeople,reminder);
    }

    @ResponseBody
    @RequestMapping("/queryManageRole")
    public ToJson queryManageRole(HttpServletRequest request,String taskId){
        return taskManageService.queryManageRole(request,taskId);
    }


}


















